﻿using Microsoft.AspNetCore.Mvc;
using yunbo.Model.BIP;
using yunbo.Model.BIQI;
using yunbo.Repositorys.BIQIRepositorys;

namespace yunbo.Controllers.BIQIControllers
{
	[Route("api/[controller]")]
	[ApiController]
	public class QMS_ZJBZController : Controller
	{
		QMS_ZJBZRepository qMS_ZJBZRepository = new QMS_ZJBZRepository();


		/// <summary>
		/// 获取质检标准
		/// </summary>
		/// <param name="state"></param>
		/// <param name="str"></param>
		/// <returns></returns>
		[HttpGet("GetQMS_ZJBZ")]
		public IActionResult GetQMS_ZJBZ(int state, string? str)
		{
			List<QMS_ZJBZ> zjbz = qMS_ZJBZRepository.GetQMS_ZJBZ(state, str);
			return Ok(zjbz);
		}

		/// <summary>
		/// 改变状态
		/// </summary>
		/// <param name="id"></param>
		/// <param name="state"></param>
		/// <returns></returns>
		[HttpPut("StateChange")]
		public IActionResult StateChange(int id, int state)
		{
			bool res = qMS_ZJBZRepository.StateChange(id, state);
			return Ok(res);
		}


		/// <summary>
		/// 新增
		/// </summary>
		/// <param name="zjbz"></param>
		/// <returns></returns>
		[HttpPost("AddQMS_ZJBZ")]
		public IActionResult AddQMS_ZJBZ(QMS_ZJBZ zjbz)
		{
			// 数据验证（可选）
			if (string.IsNullOrEmpty(zjbz.zjbz_code)
				|| string.IsNullOrEmpty(zjbz.zjbz_name)
				|| zjbz.zjbz_type <= 0
				|| string.IsNullOrEmpty(zjbz.zjbz_cp)
				|| string.IsNullOrEmpty(zjbz.zjbz_zjxm)
				)
			{
				return BadRequest("Invalid dictionary data."); // 如果数据无效，返回 400 Bad Request
			}

			bool res = qMS_ZJBZRepository.AddQMS_ZJBZ(zjbz);
			return Ok(res);
		}


		/// <summary>
		/// 修改
		/// </summary>
		/// <param name="zjbz"></param>
		/// <returns></returns>
		[HttpPut("UpdateQMS_ZJBZ")]
		public IActionResult UpdateQMS_ZJBZ(QMS_ZJBZ zjbz)
		{
			// 数据验证（可选）
			if (string.IsNullOrEmpty(zjbz.zjbz_name)
				|| zjbz.zjbz_type <= 0
				|| string.IsNullOrEmpty(zjbz.zjbz_cp)
				|| string.IsNullOrEmpty(zjbz.zjbz_zjxm)
				|| zjbz.zjbz_id <= 0
				)
			{
				return BadRequest("Invalid dictionary data."); // 如果数据无效，返回 400 Bad Request
			}

			bool res = qMS_ZJBZRepository.UpdateQMS_ZJBZ(zjbz);
			return Ok(res);
		}


		/// <summary>
		/// 删除
		/// </summary>
		/// <param name="id"></param>
		/// <returns></returns>
		[HttpPut("DelQMS_ZJBZ")]
		public IActionResult DelDW(int id)
		{
			bool res = qMS_ZJBZRepository.DelQMS_ZJBZ(id);
			return Ok(res);
		}


		/// <summary>
		/// 批量删除
		/// </summary>
		/// <param name="ids"></param>
		/// <returns></returns>
		[HttpPut("DelQMS_ZJBZs")]
		public IActionResult DelDWs(int[] ids)
		{
			bool res = qMS_ZJBZRepository.DelQMS_ZJBZs(ids);
			return Ok(res);
		}

	}
}
